package a10_动态规划;

/**
 * <p>
 * a24_完全平方数
 * </p>
 *
 * @author flyduck
 * @since 2025/2/17
 */
public class a24_完全平方数 {

    public static void main(String[] args) {
        numSquares(12);
    }

    public static int numSquares(int n) {
        int[] dp = new int[n+1];
        for (int i = 0; i < dp.length; i++) {
            dp[i] = Integer.MAX_VALUE;
        }
        dp[0] = 0;


        for (int i = 1; i * i <= n; i++) {
            for (int j = 0; j <= n; j++) {
                if(j >= ( i * i)){
                    dp[j] = Math.min(dp[j],dp[j - ( i * i)] + 1);
                }

            }
        }

        return dp[n];
    }
}
